<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-30 20:02:30
 * @LastEditTime: 2020-02-28 11:25:38
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <!-- <meta name="viewport" content="width=640,minimum-scale=0.5,maximum-scale=1.0,user-scalable=no, initial-scale=1.0" /> -->
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../../css/base.css" />
    <script type="text/javascript" src="../../script/jquery.js"></script>
    <script type="text/javascript" src="../../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../../script/vue.min.js"></script>
    <script type="text/javascript" src="../../script/vant.min.js"></script>
    <script type="text/javascript" src="../../script/fastclick.js"></script>
    <script type="text/javascript" src="../../script/base.js"></script>
    <script type="text/javascript" src="../../script/JSLINQ.js"></script>
    <style type="text/css">
        .bottom-search {
            padding-bottom: 10px;
        }

        .bottom-search .van-cell--borderless::after,
        .van-cell:last-child::after {
            display: block;
        }

        table {
            table-layout: fixed;
        }

        .ovt {
            overflow: hidden !important;
            text-overflow: ellipsis;
            -o-text-overflow: ellipsis;
            white-space: nowrap;
        }

        .ovt-c {
            white-space: normal;
            word-break: break-all;
        }

        .fix-top {
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            overflow: hidden;
        }

        .fix-bottom {
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            overflow: hidden;
            background: #fff;
        }

        .table {
            width: 100%;
            overflow-x: scroll;
        }

        .xz {
            position: fixed;
            bottom: 40px;
            right: 50%;
            background-color: rgba(51, 112, 255, 0.5);
            text-align: center;
            width: 50px;
            height: 50px;
            padding: 10px;
            border-radius: 25px;
            margin-right: -25px;
            transition: all 0.4s;
        }

        .xz_left {
            right: 50px;
        }

        .xz img {
            width: 100%;
            height: 100%;
        }

        .report-img {
            width: 60px;
            height: 60px;
        }

        .totalSummary {
            padding: 10px;
        }

        .summary {
            display: block;
            width: auto;
            float: left;
            padding: 5px;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box">
            <van-nav-bar-main :title="titleName" left-arrow @click-left="onClickLeft">
                <div slot="right">
                    <span @click="openSearch">
                        <van-icon name="search" size="18px"></van-icon>
                    </span>
                </div>
            </van-nav-bar-main>
            <div class="totalSummary">
                <span v-for="item in totalSummary" class="summary" v-if="item.name">
                    {{ item.name }}:{{ item.value }}
                </span>
            </div>
            <div class="content">
                <div class="content-refresh">

                    <van-list v-model="listLoading" :finished="listFinished" finished-text="" @load="listOnLoad">
                        <div class="table" id="table1" style="padding-bottom: 34px;" onscroll="scrollFun(1)">
                            <table>
                                <tr v-for="(row,index) in dataHead">
                                    <th v-for="(item,itemIndex) in row" :colspan="item.table_colIndex"
                                        :rowspan="item.table_rowIndex" :style="{'width':getWidth(item,index)}">
                                        <div class="ovt">{{row[item.name]}}</div>
                                    </th>
                                </tr>
                                <tr v-for="(row,index) in dataList" :class="getRowClass(row)"
                                    :style="{'background':selectIndex == index?'#c4d3ff':''}"
                                    @click="selectIndex = index">
                                    <td v-for="item in dataSortArray" @click="showFullText(row[item.name])">
                                        <div class="ovt-c">
                                            <div v-html="returnHtml(row[item.name])"></div>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>

                                    </td>
                                </tr>


                            </table>
                        </div>
                    </van-list>

                </div>



                <div class="table fix-top" id="table2">
                    <table>
                        <tr v-for="(row,index) in dataHead">
                            <th v-for="(item,itemIndex) in row" :colspan="item.table_colIndex"
                                :rowspan="item.table_rowIndex" :style="{'width':getWidth(item,index)}"
                                @click="sortData(row,item,index,itemIndex)">
                                <div class="flex-box">
                                    <div class="ovt flex-main">{{item.label}}</div>
                                    <div>
                                        <van-icon name="wap-nav" color="#b9b9b9" size="20px"
                                            v-if="sortIndex[0] != index || sortIndex[1] != itemIndex || sortType == ''">
                                        </van-icon>
                                        <van-icon name="descending" color="#3370ff" size="20px"
                                            v-if="sortIndex[0] == index && sortIndex[1] == itemIndex && sortType == 'desc'">
                                        </van-icon>
                                        <van-icon name="ascending" color="#3370ff" size="20px"
                                            v-if="sortIndex[0] == index && sortIndex[1] == itemIndex && sortType == 'asc'">
                                        </van-icon>
                                    </div>
                                </div>

                            </th>
                        </tr>
                    </table>
                </div>

                <div class="table fix-bottom" id="table3">
                    <table>
                        <tr>
                            <td v-for="item in dataSortArray" :style="{'width':item.width + 'px'}">
                                <div class="ovt"><b>{{getTotal(item)}}</b></div>
                            </td>
                        </tr>
                    </table>
                </div>

            </div>
        </div>

        <van-popup v-model="showSearch" position="bottom">
            <div class="bottom-search">
                <van-row v-for="(row,index) in searchList">
                    <van-col span="24" v-if="row.baseProperty.controlType == 'datepicker'">
                        <van-field :required="row.baseProperty.isRequired" readonly v-model="row.baseProperty.showValue"
                            :label="row.baseProperty.labelName" right-icon="arrow" @click="openDate(row,index)">
                        </van-field>
                    </van-col>
                    <van-col span="24" v-if="row.baseProperty.controlType == 'textbox'">
                        <van-field :required="row.baseProperty.isRequired" :readonly="row.baseProperty.isReadOnly"
                            v-model="row.baseProperty.showValue" :label="row.baseProperty.labelName"
                            placeholder="请输入...">
                        </van-field>
                    </van-col>
                    <van-col span="24"
                        v-if="row.baseProperty.controlType == 'select' && row.controlProperty.select.type == 1">
                        <van-field :required="row.baseProperty.isRequired" readonly v-model="row.baseProperty.showValue"
                            :label="row.baseProperty.labelName" placeholder="请选择" @click="openSelect(row,index)">
                        </van-field>
                    </van-col>

                </van-row>

            </div>
            <div class="btn-padding">
                <van-button color="#83bff6" type="primary" block style="border-radius: 0;" @click="searchData">查询
                </van-button>
            </div>
        </van-popup>


        <van-popup v-model="showDate" position="bottom">
            <van-datetime-picker v-model="currentDate" type="date" @confirm="confirmDate" @cancel="cancelDate"
                cancel-button-text="取消" />
        </van-popup>

        <van-popup v-model="showSelect" position="bottom">
            <van-picker show-toolbar :columns="selectColumns" :loading="selectLoading" :value-key="selectValueKey"
                @confirm="confirmSelect" @cancel="cancelSelect"></van-picker>
        </van-popup>

        <div class="xz" :class="tranPageText=='landscape_left'?'xz_left':''" @click="tranPage">
            <img src="../../image/xz.png" />
        </div>

    </div>
</body>

<script type="text/javascript">

    function scrollFun(index) {
        if (index == 1) {
            $("#table2").scrollLeft($("#table1").scrollLeft());
            $("#table3").scrollLeft($("#table1").scrollLeft());
        }
    }

    var vm;
    var editIndex = '';
    var isOpenImg = false;
    apiready = function () {

        var dateStr = 0;

        var photoBrowser = api.require('photoBrowser');

        api.addEventListener({
            name: 'keyback'
        }, function (ret, err) {
            if (!isOpenImg) {
                vm.onClickLeft();
            } else {
                photoBrowser.close();
            }

        });

        var o_dataList = [];
        var r_dataList = [];


        vm = new Vue({
            el: '#app',
            data: {
                showLoading: false,
                titleName: api.pageParam.titleName,
                showSearch: false,
                listLoading: false,
                listFinished: true,
                currentDate: new Date(),
                showDate: false,
                searchList: [],
                sql: '',
                dataHead: [],
                dataSortArray: [],
                dataList: [],
                sortIndex: [-1, -1],
                sortType: '',
                rowClassCol: '',
                colClassCol: '',
                tranPageText: api.pageParam.tranPageText || 'portrait_up',
                pageIndex: 1,
                pageSize: 20,
                selectIndex: -1,

                showSelect: false,
                selectLoading: false,
                selectColumns: [],
                selectValueKey: '',
                selectRealKey: '',
                totalSummary: []
            },
            created: function () {
                var that = this;
                setTimeout(function () {
                    that.initConfig();
                }, 200)
                api.setScreenOrientation({
                    orientation: that.tranPageText
                });
            },
            methods: {
                post(sql, param, callBack, async) {
                    if (async == undefined) {
                        async = false;
                    }
                    param["sql"] = sql;
                    $.ajax({
                        url: "http://" + APP.serverIP() + "/SQLData/QuerySql",
                        type: "post",
                        dataType: "json",
                        async: async,
                        data: param,
                        success: function (data) {
                            if (data.status == 200) {
                                callBack(data.data);
                            }
                            else {
                                layer.alert(data.msg);
                            }
                        }
                    });

                    //vm.handleSizeChange(vm.paging.pageIndex);
                },


                sortData: function (row, item, index, itemIndex) {
                    var that = this;
                    if (that.sortIndex[0] == index && that.sortIndex[1] == itemIndex) {
                        if (that.sortType == 'desc') {
                            that.sortType = 'asc';
                        } else if (that.sortType == 'asc') {
                            that.sortType = '';
                        } else {
                            that.sortType = 'desc';
                        }
                    } else {
                        that.sortIndex = [index, itemIndex];
                        that.sortType = 'desc';
                    }
                    if (that.sortType == 'desc') {
                        r_dataList = JSLINQ(r_dataList).OrderByDescending(function (x) { return x[item.name] }).ToArray();
                    } else if (that.sortType == 'asc') {
                        r_dataList = JSLINQ(r_dataList).OrderBy(function (x) { return x[item.name] }).ToArray();
                    } else {
                        r_dataList = o_dataList;
                    }

                    // r_dataList.sort(function(a,b){
                    //     if(that.sortType == 'desc'){
                    //         return b[item.name] - a[item.name];
                    //     }else if(that.sortType == 'asc'){
                    //         return a[item.name] - b[item.name];
                    //     }
                    // })

                    that.pageIndex = 1;
                    var dataList = [];
                    for (var i = (that.pageIndex - 1) * that.pageSize; i < that.pageIndex * that.pageSize; i++) {
                        if (r_dataList[i]) {
                            dataList.push(r_dataList[i]);
                        }
                    }

                    that.dataList = dataList;
                    that.listFinished = false;

                },
                tranPage: function () {
                    var that = this;
                    if (that.tranPageText == 'landscape_left') {
                        that.tranPageText = 'portrait_up'
                    } else if (that.tranPageText == 'portrait_up') {
                        that.tranPageText = 'landscape_left'
                    }
                    api.setScreenOrientation({
                        orientation: that.tranPageText
                    });
                },
                showFullText: function (str) {
                    var that = this;
                    if (str) {
                        str = str.toString();
                        if (str.indexOf('png') > -1 || str.indexOf('jpg') > -1 || str.indexOf('jpeg') > -1) {

                            photoBrowser.open({
                                images: ['http://' + APP.serverIP() + str],
                                activeIndex: 0,
                                bgColor: '#000'
                            }, function (ret) {
                                isOpenImg = true;
                                if (ret) {
                                    if (ret.eventType == 'click') {
                                        isOpenImg = false;
                                        photoBrowser.close();
                                    }
                                }
                            })
                        } else {
                            layer.open({
                                content: str,
                                skin: 'msg',
                                offset: '100px',
                                time: 5
                            });
                        }
                    }
                },
                returnHtml(str) {
                    if (str) {
                        str = str.toString();
                        if (str.indexOf('png') > -1 || str.indexOf('jpg') > -1 || str.indexOf('jpeg') > -1) {
                            return '<img class="report-img" src="http://' + APP.serverIP() + str + '" />'
                        } else {
                            return str;
                        }
                    } else {
                        return str;
                    }
                },
                getWidth: function (item, index) {
                    var that = this;

                    var width = 0;
                    var repeatDataHead = function (z, st) {
                        if (that.dataHead[z]) {
                            var x = 0;
                            for (var i in that.dataHead[z]) {
                                if (st.name == that.dataHead[z][i].parentName) {
                                    x = 1;
                                    repeatDataHead(z + 1, that.dataHead[z][i]);
                                }
                            }
                            if (!x) {
                                width += Number(st.width);
                            }
                        } else {
                            width += Number(st.width);
                        }
                    }
                    repeatDataHead(index + 1, item);
                    return width + 'px';
                },
                getRowClass: function (row) {
                    var that = this;
                    // alert(that.rowClassCol)
                    var fun_event = new Function('row', that.rowClassCol);
                    return fun_event(row);
                },
                getTotal: function (item) {
                    var that = this;
                    if (item.total) {
                        if (item.total.indexOf('sum') >= 0) {
                            if (item.total.indexOf('$') < 0) {
                                //保留位数
                                var fixNum = 0;
                                if (item.total.indexOf(',') >= 0) {
                                    fixNum = parseInt(item.total.split(',')[1]);
                                }
                                var totalNum = 0;
                                for (var j = 0; j < r_dataList.length; j++) {
                                    var currentNum = parseFloat(r_dataList[j][item.name]);
                                    if (isNaN(currentNum)) {
                                        currentNum = 0;
                                    }
                                    totalNum += currentNum;
                                }
                                return totalNum.toFixed(fixNum);
                            }
                            else {
                                var sumPart = item.total.split('$')[0];
                                //保留位数
                                var fixNum = 0;
                                if (sumPart.indexOf(',') >= 0) {
                                    fixNum = parseInt(sumPart.split(',')[1]);
                                }
                                var totalNum = 0;
                                for (var j = 0; j < r_dataList.length; j++) {
                                    var currentNum = parseFloat(r_dataList[j][item.name]);
                                    if (isNaN(currentNum)) {
                                        currentNum = 0;
                                    }
                                    totalNum += currentNum;
                                }
                                var subTotalData = totalNum.toFixed(fixNum);

                                var totalNum2 = 0;
                                for (var j = 0; j < r_dataList.length; j++) {
                                    var currentNum = parseFloat(r_dataList[j][item.total.split('$')[1]]);
                                    if (isNaN(currentNum)) {
                                        currentNum = 0;
                                    }
                                    totalNum2 += currentNum;
                                }


                                subTotalData += "(" + (totalNum * 100.0 / totalNum2).toFixed(2) + "%)";
                                return subTotalData;
                            }



                            // var t = 0;
                            // for (var i in r_dataList) {
                            //     if (r_dataList[i][item.name]) {
                            //         t += r_dataList[i][item.name];
                            //     }
                            // }
                            // return t.toFixed(2);
                        } else if (item.total.indexOf('avg') > -1) {
                            //保留位数
                            var fixNum = 0;
                            if (item.total.indexOf(',') >= 0) {
                                fixNum = parseInt(item.total.split(',')[1]);
                            }
                            var operData = item.total.split(',')[0].substring(item.total.split(',')[0].indexOf('(') + 1, item.total.split(',')[0].indexOf(')'));
                            var divisorCol = operData.split('/')[0];
                            var dividendCol = operData.split('/')[1];
                            // var divisorIndex = 0, dividendIndex = 0;
                            // for (var k = 0; k < param.columns.length; k++) {
                            //     if (param.columns[k].property == divisorCol) {
                            //         divisorIndex = k;
                            //     }
                            //     if (param.columns[k].property == dividendCol) {
                            //         dividendIndex = k;
                            //     }
                            // }

                            var totalNum2 = 0;
                            for (var j = 0; j < r_dataList.length; j++) {
                                var currentNum = parseFloat(r_dataList[j][divisorCol]);
                                if (isNaN(currentNum)) {
                                    currentNum = 0;
                                }
                                totalNum2 += currentNum;
                            }
                            var totalNum3 = 0;
                            for (var j = 0; j < r_dataList.length; j++) {
                                var currentNum = parseFloat(r_dataList[j][dividendCol]);
                                if (isNaN(currentNum)) {
                                    currentNum = 0;
                                }
                                totalNum3 += currentNum;
                            }





                            var totalResult = totalNum2 * 1.0 / totalNum3;
                            if (item.total.indexOf('%') >= 0) {
                                totalResult = (totalResult * 100).toFixed(fixNum) + "%";
                            }
                            else {
                                totalResult = totalResult.toFixed(fixNum)
                            }
                            return totalResult;
                        }
                    } else {
                        return '';
                    }
                },
                initConfig: function () {
                    var that = this;
                    $.ajax({
                        url: "http://" + APP.serverIP() + "/ReportList/GetDataByName",
                        async: true,
                        data: {
                            objName: api.pageParam.objName
                        },
                        type: "post",
                        dataType: 'json',
                        success: function (res) {

                            if (res.status == 200) {
                                var data = res.data;
                                // console.log(JSON.stringify(data))
                                var searchList = JSON.parse(data.ds[0].searchDesignConfig);
                                var x = 0;
                                for (var i in searchList) {
                                    searchList[i].baseProperty.value = '';
                                    searchList[i].baseProperty.showValue = '';

                                    if (searchList[i].baseProperty.isRequired) {
                                        x = 1;
                                    }
                                    if (searchList[i].baseProperty.defaultValue) {
                                        searchList[i].baseProperty.value = vm.getSYDefaultValue(searchList[i].baseProperty.defaultValue);
                                        searchList[i].baseProperty.showValue = vm.getSYDefaultValue(searchList[i].baseProperty.defaultValue);
                                    }


                                }
                                that.searchList = searchList;
                                if (api.pageParam.Range) {
                                    let cxdate = that.searchList.find(item => item.baseProperty.controlName == 'CX_SDate');
                                    cxdate.baseProperty.value = '';
                                    cxdate.baseProperty.showValue = '';
                                    let cxpname = that.searchList.find(item => item.baseProperty.controlName == 'ProductName');
                                    cxpname.baseProperty.value = api.pageParam.ProductName;
                                    cxpname.baseProperty.showValue = api.pageParam.ProductName;
                                    let cxrange = that.searchList.find(item => item.baseProperty.controlName == 'Range');
                                    cxrange.baseProperty.value = api.pageParam.Range;
                                    cxrange.baseProperty.showValue = api.pageParam.Range;
                                }
                                // console.log(JSON.stringify(that.searchList))

                                that.sql = data.ds[0].sql;
                                if (data.ds[0].rowClassCol) {
                                    that.rowClassCol = data.ds[0].rowClassCol.replace(/\[["|'](.*?)["|']\]/g, 'row$&');
                                }
                                if (!x) {
                                    that.getDataList();
                                } else {
                                    that.showSearch = true;
                                }

                            }
                        }
                    });
                },
                getDataList: function () {
                    var that = this;
                    that.showLoading = true;
                    that.pageIndex = 1;
                    var sqlParam = [];
                    for (var i in that.searchList) {
                        if (that.searchList[i].baseProperty.isRequired && !that.searchList[i].baseProperty.showValue) {
                            layer.open({
                                content: '请输入' + that.searchList[i].baseProperty.labelName,
                                skin: 'msg',
                                time: 2
                            });
                            break;
                        }
                        if (that.searchList[i].baseProperty.controlType == 'textbox') {
                            sqlParam.push({
                                key: that.searchList[i].baseProperty.controlName,
                                value: that.searchList[i].baseProperty.showValue
                            })
                        } else {
                            sqlParam.push({
                                key: that.searchList[i].baseProperty.controlName,
                                value: that.searchList[i].baseProperty.value
                            })
                        }

                    }
                    sqlParam.push({
                        key: 'P_UserID',
                        value: APP.getUserInfo().UserID
                    })
                    api.showProgress();
                    $.ajax({
                        url: "http://" + APP.serverIP() + "/SQLData/GetDataBySql",
                        async: true,
                        data: {
                            sql: that.sql,
                            sqlParam: sqlParam
                        },
                        type: "post",
                        dataType: 'json',
                        success: function (res) {
                            if (res.status == 200) {
                                //返回数据本身
                                var data = res.data;
                                // that.dataHead = data.ds1;
                                if (data.ds3) {
                                    vm.totalSummary = data.ds3;
                                }


                                var topHead = [];

                                for (var i in data.ds1) {
                                    if (!data.ds1[i].parentName) {
                                        topHead.push(data.ds1[i]);
                                    }

                                }
                                var totalDataHead = [topHead];

                                var repeatHead = function (array) {
                                    var newArray = [];
                                    for (var i in array) {
                                        for (var j in data.ds1) {
                                            if (array[i].name == data.ds1[j].parentName) {
                                                newArray.push(data.ds1[j]);
                                            }
                                        }

                                    }
                                    if (newArray.length) {
                                        totalDataHead.push(newArray);
                                        repeatHead(newArray);
                                    } else {
                                        for (var i = 0; i < totalDataHead.length; i++) {
                                            if (i == totalDataHead.length - 1) {
                                                for (var m in totalDataHead[i]) {
                                                    totalDataHead[i][m].table_colIndex = 1;
                                                    totalDataHead[i][m].table_rowIndex = 1;
                                                }

                                            } else {
                                                for (var m in totalDataHead[i]) {
                                                    var x = 0;
                                                    for (var n in totalDataHead[i + 1]) {
                                                        if (totalDataHead[i][m].name == totalDataHead[i + 1][n].parentName) {
                                                            x++;
                                                        }
                                                    }
                                                    if (x) {
                                                        totalDataHead[i][m].table_colIndex = x;
                                                        totalDataHead[i][m].table_rowIndex = 1;
                                                    } else {
                                                        totalDataHead[i][m].table_colIndex = 1;
                                                        totalDataHead[i][m].table_rowIndex = totalDataHead.length - i;
                                                    }
                                                }
                                            }

                                        }

                                        var dataSortArray = [];
                                        var repeatTotalDataHead = function (d) {
                                            var x = 0;
                                            for (var j in data.ds1) {
                                                if (d.name == data.ds1[j].parentName) {
                                                    x = 1;
                                                    repeatTotalDataHead(data.ds1[j].name);
                                                }
                                            }
                                            if (!x) {
                                                dataSortArray.push(d);
                                            }
                                        }


                                        for (var i in totalDataHead[0]) {
                                            var x = 0;
                                            for (var j in data.ds1) {
                                                if (totalDataHead[0][i].name == data.ds1[j].parentName) {
                                                    x = 1;
                                                    repeatTotalDataHead(data.ds1[j]);
                                                }
                                            }
                                            if (!x) {
                                                dataSortArray.push(totalDataHead[0][i])
                                            }
                                        }


                                        that.dataSortArray = dataSortArray;

                                        that.dataHead = totalDataHead;

                                        r_dataList = data.ds2;
                                        o_dataList = JSON.parse(JSON.stringify(data.ds2));

                                        var dataList = [];
                                        for (var i = (that.pageIndex - 1) * that.pageSize; i < that.pageIndex * that.pageSize; i++) {
                                            if (r_dataList[i]) {
                                                dataList.push(r_dataList[i]);
                                            }
                                        }

                                        that.dataList = dataList;
                                        that.listFinished = false;

                                        api.hideProgress();

                                    }
                                }
                                repeatHead(topHead);
                            } else {
                                api.hideProgress();
                            }
                        }
                    });

                },
                listOnLoad: function () {
                    var that = this;
                    that.pageIndex++;
                    var dataList = [];
                    setTimeout(function () {
                        for (var i = (that.pageIndex - 1) * that.pageSize; i < that.pageIndex * that.pageSize; i++) {
                            if (r_dataList[i]) {
                                dataList.push(r_dataList[i]);
                            }
                        }
                        that.listLoading = false;
                        if (dataList.length) {
                            that.dataList = that.dataList.concat(dataList);
                        } else {
                            that.listFinished = true;
                        }
                    }, 200)


                },
                openSearch: function () {
                    var that = this;
                    that.showSearch = true;
                },
                searchData: function () {
                    var that = this;
                    that.showSearch = false;

                    that.getDataList();
                },
                openSelect: function (row, index) {
                    var that = this;

                    if (row.baseProperty.isReadOnly) return;
                    editIndex = index;

                    var sql = "select * from (" + row.controlProperty.select.dataSource + ")t";
                    var filter = row.controlProperty.select.formSQL;

                    for (var key in that.formData) {
                        var value = "'" + that.formData[key] + "'";
                        var filterEvent = new Function("filter.replace(/" + "@" + key + "/g,value)");
                        filterEvent();
                    }
                    sql += filter ? (' where ' + filter) : '';

                    if (row.controlProperty.select.type == 1) {
                        that.selectColumns = [];
                        that.selectValueKey = row.controlProperty.select.displayValue;
                        that.selectRealKey = row.controlProperty.select.hiddenValue;
                        that.showSelect = true;
                        that.selectLoading = true;

                        $.ajax({
                            url: "http://" + APP.serverIP() + "/SQLData/GetDataBySql",
                            async: true,
                            data: {
                                sql: sql
                            },
                            type: "post",
                            dataType: 'json',
                            success: function (res) {
                                if (res.status == 200) {
                                    var data = res.data;

                                    that.selectColumns = data.ds;
                                    that.selectLoading = false;

                                }
                            }
                        });

                    }
                },
                confirmSelect: function (value, index) {
                    var that = this;
                    that.searchList[editIndex].baseProperty.showValue = that.selectColumns[index][that.selectValueKey];
                    that.searchList[editIndex].baseProperty.value = that.selectColumns[index][that.selectRealKey];
                    that.showSelect = false;
                    that.selectColumns = [];
                },
                cancelSelect: function () {
                    var that = this;
                    that.showSelect = false;
                    that.selectColumns = [];
                },
                openDate: function (row, index) {
                    var that = this;
                    if (row.baseProperty.isReadOnly) {
                        return;
                    }
                    editIndex = index;
                    if (row.baseProperty.showValue) {
                        that.currentDate = new Date(row.baseProperty.showValue);
                    } else {
                        that.currentDate = new Date();
                    }

                    that.showDate = true;

                },
                confirmDate: function (value) {
                    var that = this;
                    that.searchList[editIndex].baseProperty.value = APP.getFormatDate(value).split(' ')[0];
                    that.searchList[editIndex].baseProperty.showValue = APP.getFormatDate(value).split(' ')[0];
                    that.showDate = false;
                },
                cancelDate: function (value) {
                    var that = this;
                    that.searchList[editIndex].baseProperty.value = '';
                    that.searchList[editIndex].baseProperty.showValue = '';
                    that.showDate = false;
                },
                getSYDefaultValue(funcName) {
                    if (funcName.indexOf("getdate()") >= 0) {
                        var date;
                        if (funcName == "getdate()") {
                            date = new Date();
                        } else {
                            date = new Date();
                            Date.prototype.DateAdd = function (strInterval, Number) {
                                var dtTmp = this;
                                switch (strInterval) {
                                    case 's':
                                        return new Date(Date.parse(dtTmp) + (1000 * Number));
                                    case 'n':
                                        return new Date(Date.parse(dtTmp) + (60000 * Number));
                                    case 'h':
                                        return new Date(Date.parse(dtTmp) + (3600000 * Number));
                                    case 'd':
                                        return new Date(Date.parse(dtTmp) + (86400000 * Number));
                                    case 'w':
                                        return new Date(Date.parse(dtTmp) + ((86400000 * 7) * Number));
                                    case 'q':
                                        return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number * 3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
                                    case 'm':
                                        return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
                                    case 'y':
                                        return new Date((dtTmp.getFullYear() + Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
                                }
                            }
                            var addFun = funcName.split('.')[1];
                            eval("date=date." + addFun);
                        }
                        var seperator1 = "-";
                        var seperator2 = ":";
                        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                        var strDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
                            " " + date.getHours() + seperator2 + date.getMinutes() +
                            seperator2 + date.getSeconds();
                        return currentdate;
                    }
                    else {
                        return eval(funcName);
                    }
                },
                onClickLeft: function () {
                    api.setScreenOrientation({
                        orientation: 'portrait_up'
                    })
                    api.closeWin();
                }
            }
        })
    };
</script>

</html>